﻿using RegisterationCommon.Common;
using RegisterationCommon.Preschools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace RegisterationSystem.Space_Preschools
{
    public partial class passaspx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //获取用户名
                username.InnerHtml = Session["myAccountName"].ToString();
              string S = Cookies.Get("ID");
            }
        }

        protected void btnadd_Click(object sender, EventArgs e)
        {
            //string id = Request.QueryString["id"];
            //string S = Cookies.Get("ID");
            //判断原密码是否正确
            int id ;
            string AccountPswd = "";
            DataTable dt = DBAction.GetDTFromSQL("select * from dbo.Preschools where AccountName='" + Session["myAccountName"].ToString()+"'");
            if (dt.Rows.Count == 1)
            {
                id = int.Parse(dt.Rows[0]["ID"].ToString());
                AccountPswd = dt.Rows[0]["AccountPswd"].ToString();



            if (BaseLibrary.ConvertToMD5(OldAccountPswd.Value.ToLower()) != AccountPswd)
            {
                //Message.Send(20006);
                Message.Send(20006);
                Message.Show("密码不正确");
                return;
            }
            //Account.Current.ID =Convert.ToInt64( Cookies.Get("AccountID"));
            //获取用户修改密码(MD5加密)
             if (AccountPswd == BaseLibrary.ConvertToMD5(NewAccountPswd.Value.ToLower()))
            {
                //新密码于原密码相同
                //修改成功
                //Message.Send(10028);
                Message.Show("新密码于原密码相同,无需修改");
                return;
            }
             if (BaseLibrary.ConvertToMD5(OldAccountPswd.Value.ToLower()) == AccountPswd && AccountPswd != BaseLibrary.ConvertToMD5(NewAccountPswd.Value.ToLower()))
            {
                Preschools.Current.UpdateAccountPwd(id, BaseLibrary.ConvertToMD5(NewAccountPswd.Value.ToLower()));
                //修改成功
                Message.Send(20005);
               // Message.Show("密码修改成功");
            }
            else
            {
                //修改失败
                Message.Send(20007);
                return;
            }


            }
        }
    }
}